package sw.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import sw.entity.Student;
import sw.repo.StudentRepo;

@Controller
public class StudentController {
	@Autowired //引入数据库接口
	private StudentRepo studentRepository;

	@GetMapping("/student") //显示班级列表视图
	public String showStudentPage(Model model){
		Iterable<Student> student = studentRepository.findAll();
		model.addAttribute("student",student);
		return "student/index";
	}
	
	@GetMapping("/student/form")
	public String showStudentAddPage(){
		return "student/form";
	}
	
	@PostMapping("/student/student")
	public String showForm(Student student){
		studentRepository.save(student);
		return "student/student";
	}
}
